import React from 'react';
const loadjs = window.loadjs;
import isEqual from "lodash/isEqual";

export default class CenterLoglist extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            hasLoad: false,
            store: null,
            visiable: false,
            requestid: ''
        };
        this.signviewPoistion = this.signviewPoistion.bind(this);
        this.onCancel = this.onCancel.bind(this);
    }
   
    shouldComponentUpdate(nextProps, nextState) {
        return !isEqual(this.state, nextState) || !isEqual(this.props, nextProps)
    }

    signviewPoistion(value, id, type) {
        if(value) {
            const init = () => {
                const {WfCenterLogListStore} = window.weaWorkflowPublic;
                const store = new WfCenterLogListStore();
                this.setState({hasLoad: true, store: store});
            }
            loadjs.isDefined('workflowPublic') ? loadjs.ready('workflowPublic', init) : loadjs([
                "/spa/workflow/static4public/index.js",
                "/spa/workflow/static4public/index.css"
            ], 'workflowPublic', init);
        }
        this.setState({
            visiable: true,
            requestid: value,
            f_weaver_belongto_userid: id,
            f_weaver_belongto_usertype: type
        });
    }
    onCancel(v){
        $('#wflist_' +this.state.requestid+ 'span').html('');
        this.setState({
          visiable: false, 
          requestid: -1,
          f_weaver_belongto_userid: 0,
          f_weaver_belongto_usertype: 0
        });
        window.backlogRefresh && window.backlogRefresh();
    }
    render() {
        const {
          hasLoad, store, visiable, requestid,
          f_weaver_belongto_userid, f_weaver_belongto_usertype
        } = this.state;
        if (hasLoad) {
            const {WfCenterLogList} = window.weaWorkflowPublic;
            if (visiable && requestid > -1) {
              store.init({requestid, f_weaver_belongto_userid, f_weaver_belongto_usertype}, visiable);
            }
            return (
                <WfCenterLogList ecId={`${this && this.props && this.props.ecId || ''}_WfCenterLogList@jr86ig`} 
                  onCancel={this.onCancel}
                  wfCenterLogListStore={store}
                />
            )
        } else {
            return (<div></div>);
        }
    }
}